import PKScene from '../SceneJs/PKScene';


const {ccclass, property} = cc._decorator;

@ccclass
export default class PKMatch extends cc.Component {

    @property(cc.Label)
    time: cc.Label = null;
    @property(cc.Label)
    robotName: cc.Label = null;
    @property(cc.Sprite)
    robotHead: cc.Label = null;
    @property(cc.Sprite)
    radial : cc.Sprite = null;
    @property(cc.Node)
    robotFrame : cc.Node= null;
    @property(cc.Node)
    shanxing : cc.Node= null;
    @property(cc.Node)
    srcTxt : cc.Node= null;

    waitTime = null;
    timer = 0;
    Interval = null;

    onEnable(){
        this.srcTxt.active = false;
        this.robotFrame.active = false;
        this.time.node.active = true;
        this.time.string = '0';
        // this.radial.fillRange = 0;
        this.waitTime = Math.floor(Math.random()*10) + 3;
    }
    onDisable(){
        clearInterval(this.Interval);
    }

    update (dt) {
        var self = this;
        this.Interval = setTimeout(()=>{
            self.shanxing.angle -= 8;
        },1000);
        // let fr = this.radial.fillRange;
        // fr += 0.01;
        // if (fr > 1)
        //     fr = 0;
        // this.radial.fillRange = fr;
        if (this.waitTime == null)
            return;
        
        this.timer +=dt;
        this.time.string = '' + Math.floor(this.timer);
        if (this.timer >= this.waitTime){
            this.waitTime = null;
            this.time.node.active = false;
            this.srcTxt.active = true;
            this.robotFrame.active = true;
            (cc.find('Canvas').getComponent('PKScene') as PKScene).showStep(2);
        }
    }
}
